﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcmyjobs.Web.users
{
    public partial class user_collect : BasePage
    {
        lcmyjobs.BLL.user_basic bub = new lcmyjobs.BLL.user_basic();
        DataSet ds;
        int count = 0;
        int id = 0;

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                this.Title = string.Format("个人管理中心—我的工作：职位收藏夹   {0}", Application["webname"].ToString());
                if (Session["user_id"] == null)
                {
                    Response.Redirect("userlogin.html");
                }
                else
                {
                    int id = int.Parse(Session["user_id"].ToString());
                    this.lblName.Text = Session["user_name"].ToString();
                    getcout(id);
                    //btnDel.Attributes.Add("onclick", "return confirm(\"你确认要删除吗？\")");

                }




            }

        }
        public string showday(string a)
        {
            int i = int.Parse(a);
            if (i >= 0)
                return a;
            else
                return "过期";
        }
        protected void getcout(int atid)
        {
            ds = bub.PageUserCollect(atid, 1, AspNetPager1.PageSize, out count);
            AspNetPager1.RecordCount = count;
            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();

        }
        protected void bind(int atid)
        {
            ds = bub.PageUserCollect(atid, AspNetPager1.StartRecordIndex, AspNetPager1.PageSize, out count);
            AspNetPager1.RecordCount = count;
            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();

        }



        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            if (Session["user_id"] != null)
            {
                int id = int.Parse(Session["user_id"].ToString());
                bind(id);
            }

        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                LinkButton linkbtnDel = (LinkButton)e.Row.FindControl("LinkButton1");
                //linkbtnDel.Attributes.Add("onclick", "return confirm(\"你确认要删除吗\")");

            }
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string ID = GridView1.DataKeys[e.RowIndex].Value.ToString();
            bub.deletecollects(ID);
            if (Session["user_id"] != null)
            {
                int id = int.Parse(Session["user_id"].ToString());
                bind(id);
            }
        }

        private string GetSelIDlist()
        {
            string idlist = "";
            bool BxsChkd = false;
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                CheckBox ChkBxItem = (CheckBox)GridView1.Rows[i].FindControl("chku");
                if (ChkBxItem != null && ChkBxItem.Checked)
                {
                    BxsChkd = true;
                    //#warning 代码生成警告：请检查确认Cells的列索引是否正确
                    if (GridView1.DataKeys[i].Value != null)
                    {
                        idlist += GridView1.DataKeys[i].Value.ToString() + ",";
                    }
                }
            }
            if (BxsChkd)
            {
                idlist = idlist.Substring(0, idlist.LastIndexOf(","));
            }
            return idlist;
        }




        protected void btnDelete_Click(object sender, EventArgs e)
        {
            string idlist = GetSelIDlist();
            if (idlist.Trim().Length == 0)
                return;
            bub.deletecollects(idlist);
            if (Session["user_id"] != null)
            {
                int id = int.Parse(Session["user_id"].ToString());
                bind(id);
            }
        }
    }
}